// Fill out your copyright notice in the Description page of Project Settings.

#include "MPU6050Test.h"
#include "MPU6050Actor.h"


// Sets default values
AMPU6050Actor::AMPU6050Actor()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AMPU6050Actor::BeginPlay()
{
	Super::BeginPlay();
	
	mpuServer = new MPU6050Server(8000, this);
}

void AMPU6050Actor::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	delete mpuServer;

	Super::EndPlay(EndPlayReason);
}

// Called every frame
void AMPU6050Actor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	CurrentPosition = actorPose.GetLocation();
	CurrentRotation = actorPose.GetRotation();
}

void AMPU6050Actor::OnAcceleration(float x, float y, float z)
{
	UE_LOG(LogClass, Log, TEXT("OnAcceleration: %4.3f\t%4.3f\t%4.3f\t"), x, y, z);
	//EventAcceleration(x, y, z);
	actorPose.InputAcceleration(x, y, z);
}

void AMPU6050Actor::OnAngularSpeed(float x, float y, float z)
{
	UE_LOG(LogClass, Log, TEXT("OnAngularSpeed: %4.3f\t%4.3f\t%4.3f\t"), x, y, z);
	//EventAngularSpeed(x, y, z);
}

void AMPU6050Actor::OnAngle(float roll, float pitch, float yaw)
{
	//UE_LOG(LogClass, Log, TEXT("OnAngle: %4.2f\t%4.2f\t%4.2f\t"), roll, pitch, yaw);
	//EventAngle(roll, pitch, yaw);
	actorPose.InputRotation(roll, pitch, yaw);
}
